package top.zhangjianyong.tools.factory;

import com.alibaba.fastjson.JSONObject;
import top.zhangjianyong.tools.entity.Holiday;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class HolidayFactory {
    private final static DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static Holiday create() {
        return new Holiday();
    }

    public static Holiday create(JSONObject jsonObject) {
        String name = jsonObject.getString("name");
        Boolean isHoliday = jsonObject.getBoolean("holiday");
        String dateStr = jsonObject.getString("date");
        Holiday holiday = create();
        holiday.setName(name);
        holiday.setIsHoliday(isHoliday);
        LocalDate date = LocalDate.parse(dateStr, DTF);
        holiday.setDate(date);
        return holiday;

    }

}
